﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace Xinnos.Lca.Yacht.Analyzer.View
{
    /// <summary>
    /// WorkBreakdownStructureTabPanel.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class WorkBreakdownStructureTabPanel : UserControl
    {
        private WorkBreakdownStructuresViewModel mViewModel = null;
        public WorkBreakdownStructureTabPanel()
        {
            InitializeComponent();
            if (null == mViewModel)
            {
                mViewModel = WorkBreakdownStructuresViewModel.GetInstance();
                this.DataContext = mViewModel;
            }
        }

        private void OnCanExecuteNewCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = true;
        }
        private void OnExecuteNewCommand(object sender, ExecutedRoutedEventArgs e)
        {
            WorkBreakdownStructureGroupPanel _panel = new WorkBreakdownStructureGroupPanel();
            CommonDialog _dialog = new CommonDialog(_panel);
            _dialog.Title = "YWBS 그룹 생성";
            _dialog.Height = 120;
            if (true == _dialog.ShowDialog())
            {
                WorkBreakdownStructureGroupViewModel _group = _panel.DataContext as WorkBreakdownStructureGroupViewModel;
                mViewModel.Groups.Add(_group);
                mViewModel.Group = _group;
            }
        }

        private void OnCanExecuteReplaceCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = (null == mViewModel) ? false : null != mViewModel.Group;
        }
        private void OnExecuteReplaceCommand(object sender, ExecutedRoutedEventArgs e)
        {
            WorkBreakdownStructureGroupPanel _panel = new WorkBreakdownStructureGroupPanel();
            _panel.DataContext = mViewModel.Group;
            CommonDialog _dialog = new CommonDialog(_panel);
            _dialog.Title = "YWBS 그룹 수정";
            _dialog.Height = 120;
            _dialog.ShowDialog();
        }

        private void OnCanExecuteRemoveCommand(object sender, CanExecuteRoutedEventArgs e)
        {
            e.CanExecute = (null == mViewModel) ? false : null != mViewModel.Group;
        }
        private void OnExecuteRemoveCommand(object sender, ExecutedRoutedEventArgs e)
        {
            mViewModel.Groups.Remove(mViewModel.Group);
        }
    }
}
